package com.fansl.allround.open.helper.sms;

import cn.hutool.core.util.RandomUtil;
import com.fansl.allround.open.api.constant.enums.juhe.SmsTemplateEnum;
import com.fansl.allround.open.api.entity.sms.SendSmsCodePO;
import com.fansl.allround.open.api.entity.sms.SendSmsMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author fansl
 * @Description: 短信绑定消息模板
 * @date 2019/11/4 16:24
 */
@Slf4j
@Component
public class BindMessageTemplateExecutor implements SmsMessageTemplateExecutor {
    /**
     * 创建消息模板
     * @param smsCodePO
     * @return
     * @throws Exception
     */
    @Override
    public SendSmsMessage createMessageTemplate(SendSmsCodePO smsCodePO) throws Exception {
        int templateId = SmsTemplateEnum.TEMPLATE_BIND.getTemplateId();
        String code = createSmsCode(6);
        String templateValue = "#code#="+code;
        SendSmsMessage message = new SendSmsMessage();
        message.setTplId(templateId)
                .setTplValue(templateValue)
                .setCode(code)
                .setMobile(smsCodePO.getMobile());
        return message;
    }
    private String createSmsCode(int codeLength){
        return RandomUtil.randomNumbers(codeLength);
    }
}
